<div class="filter">
<?php if(isset($displayCols[0])): ?>
	<select class="filters_col" id="site_buytype" name="buytype">
		<option value="">---Buy Type---</option>
		<?php foreach($filters['buy_type'] as $bt): ?>
		<option value="<?php echo $bt; ?>">
		<?php echo $bt; ?>
		</option>
		<?php endforeach; ?>
	</select>
	<?php endif; ?>
	<?php if(isset($displayCols[1])): ?>
	<select class="filters_col" id="site_mediatype" name="mediatype">
		<option value="">---Media Type---</option>
		<?php foreach($filters['media_type'] as $mt): ?>
		<option value="<?php echo $mt; ?>">
		<?php echo $mt; ?>
		</option>
		<?php endforeach; ?>
	</select>
	<?php endif; ?>
	<?php if(isset($displayCols[2])): ?>
	<select class="filters_col" id="site_publisher" name="publisher">
		<option value="">---Publisher---</option>
		<?php foreach($filters['pub'] as $pub): ?>
		<option value="<?php echo $pub; ?>">
		<?php echo $pub; ?>
		</option>
		<?php endforeach; ?>
	</select>
	<?php endif; ?>
	<?php if(isset($displayCols[3])): ?>
	<select class="filters_col" id="site_pla" name="pla">
		<option value="">---Placement---</option>
		<?php foreach($filters['pla'] as $pla): ?>
		<option value="<?php echo $pla; ?>">
		<?php echo $pla; ?>
		</option>
		<?php endforeach; ?>
	</select>
	<?php endif; ?>
	<?php if(isset($displayCols[4])): ?>
	<select class="filters_col" id="site_campaign" name="campaign">
		<option value="">---Campaign---</option>
		<?php foreach($filters['cam'] as $cam): ?>
		<option value="<?php echo $cam; ?>">
		<?php echo $cam; ?>
		</option>
		<?php endforeach; ?>
	</select>
	<?php endif; ?>
	<?php if(isset($displayCols[5])): ?>
	<select class="filters_col" id="site_creative" name="creative">
		<option value="">---Creative---</option>
		<?php foreach($filters['cre'] as $cre): ?>
		<option value="<?php echo $cre; ?>">
		<?php echo $cre; ?>
		</option>
		<?php endforeach; ?>
	</select>
	<?php endif; ?>
	<?php if(isset($displayCols[6])): ?>
	<select class="filters_col" id="site_monetization" name="monetization">
		<option value="">---Monetization---</option>
		<?php foreach($filters['monetization'] as $monetization): ?>
		<option value="<?php echo $monetization; ?>">
		<?php echo $monetization; ?>
		</option>
		<?php endforeach; ?>
	</select>
	<?php endif; ?>
	<?php if(isset($displayCols[7])): ?>
	<select class="filters_col" id="site_sites" name="sites">
		<option value="">---Sites---</option>
		<?php foreach($filters['site'] as $site): ?>
		<option value="<?php echo $site; ?>">
		<?php echo $site; ?>
		</option>
		<?php endforeach; ?>
	</select>
	<?php endif; ?>
	<input type="button" id="site_filter" value=">>>Filter" />
</div>

<table class="tablesorter" id="tab1">
	<thead>
		<tr>
			<th class="col_date">Date<span class="close">X</span></th>
			<?php if(isset($displayCols[0])):?>
			<th class="col_buy">Buy Type<span class="close">X</span></th>
			<?php endif;?>
			<?php if(isset($displayCols[1])):?>
			<th class="col_media">Publisher Type<span class="close">X</span></th>
			<?php endif;?>
			<?php if(isset($displayCols[2])):?>
			<th class="col_publisher">Publisher<span class="close">X</span></th>
			<?php endif;?>
			<?php if(isset($displayCols[3])):?>
			<th class="col_placement">Placement<span class="close">X</span></th>
			<?php endif;?>
			<?php if(isset($displayCols[4])):?>
			<th class="col_campaign">Campaign<span class="close">X</span></th>
			<?php endif;?>
			<?php if(isset($displayCols[5])):?>
			<th class="col_creative">Creative<span class="close">X</span></th>
			<?php endif;?>
			<?php if(isset($displayCols[6])):?>
			<th class="col_monetization">Monetization<span class="close">X</span>
			</th>
			<?php endif;?>
			<?php if(isset($displayCols[7])):?>
			<th class="col_site">Site<span class="close">X</span></th>
			<?php endif;?>

			<th class="col_landing">Landing<span class="close">X</span></th>
			<th class="col_short">Short Leads<span class="close">X</span></th>
			<th class="col_short_percentage">Short Leads %<span class="close">X</span>
			</th>
			<th class="col_coshort">Short Reg Coreg<span class="close">X</span></th>
			<th class="col_coshort_percentage">Short Reg Coreg %<span
				class="close">X</span></th>
			<th class="col_long">Long Leads<span class="close">X</span></th>
			<th class="col_long_percentage">Long Leads %<span class="close">X</span>
			</th>
			<th class="col_colong">Long Reg Coreg<span class="close">X</span></th>
			<th class="col_colong_percentage">Long Reg Coreg %<span class="close">X</span>
			</th>
			<th class="col_update">Update Profile<span class="close">X</span></th>
			<th class="col_coupdate">Update Profile Coreg<span class="close">X</span>
			</th>
			<th class="col_coupdate_percentage">Update Profile Coreg %<span
				class="close">X</span></th>
			<th class="col_confirmed">Confirmed<span class="close">X</span></th>
			<th class="col_confirmed_percentage">Confirmed %<span class="close">X</span>
			</th>
			<th class="col_coconfirmed">Confirmed Coreg<span class="close">X</span>
			</th>
			<th class="col_coconfirmed_percentage">Confirmed Coreg %<span
				class="close">X</span></th>
			<th class="col_costart">Daily Coreg Start<span class="close">X</span>
			</th>
			<th class="col_coend">Daily Coreg End<span class="close">X</span></th>
			<th class="col_co_percentage">Daily Coreg %<span class="close">X</span>
			</th>
			<th class="col_offer">Offer Completed<span class="close">X</span></th>
			<th class="col_offer-user">Offer / User<span class="close">X</span></th>
			<th class="col_rewarded">Tokens Rewarded<span class="close">X</span>
			</th>
			<th class="col_tokens-user">Tokens / User<span class="close">X</span>
			</th>
		</tr>
	</thead>
	<tbody>
	<?php
	if((!empty($reportItems)) && $reporttype=="1"):
	$durations = Util::getReportDuration($duration);
	foreach ($reportItems as $k=>$reportItem): 
			$date['start'] = $reportItem['date'];
			if($interval == 2){
				list($year, $week) = str_split($reportItem['date'], 4);
				$date = Util::getStartAndEndDate($week, $year);
			}
	?>
		<tr>
			<td class="col_date"><?php echo $date['start'];?> <?php if($interval==2){ echo '---'.$date['end'];} ?></td>
			<?php if(isset($displayCols[0])): ?>
				<td class="col_buy"><?php echo $reportItem['buy_type'];?></td>
			<?php endif; ?>
			<?php if(isset($displayCols[1])): ?>
				<td class="col_media"><?php echo $reportItem['media_type'];?></td>
			<?php endif; ?>
			<?php if(isset($displayCols[2])): ?>
				<td class="col_publisher" id="pub<?php echo $k; ?>"><?php echo $reportItem['pub'];?></td>
			<?php endif; ?>
			<?php if(isset($displayCols[3])): ?>
				<td class="col_placement" id="pla<?php echo $k; ?>"><?php echo $reportItem['pla'];?></td>
			<?php endif; ?>
			<?php if(isset($displayCols[4])): ?>
				<td class="col_campaign" id="cam<?php echo $k; ?>"><?php echo $reportItem['cam'];?></td>
			<?php endif; ?>
			<?php if(isset($displayCols[5])): ?>
				<td class="col_creative"><?php echo $reportItem['cre'];?></td>
			<?php endif; ?>
			<?php if(isset($displayCols[6])): ?>
				<td class="col_monetization"><?php echo $reportItem['monetization'];?></td>
			<?php endif; ?>
			<?php if(isset($displayCols[7])): ?>
				<td class="col_site"><?php echo $reportItem['site'];?></td>
			<?php endif; ?>
			<td class="col_landing"><?php echo $reportItem['landing'];?></td>
			<td class="col_short"><?php echo $reportItem['basic_reg'];?></td>
			<td class="col_short_percentage"><?php echo Util::divide($reportItem['basic_reg'], $reportItem['landing'], 2, true);?></td>
			<td class="col_coshort"><?php echo $reportItem['basic_reg_coreg'];?></td>
			<td class="col_coshort_percentage"><?php echo Util::divide($reportItem['basic_reg_coreg'], $reportItem['basic_reg'], 2, true);?></td>
			<td class="col_long"><?php echo $reportItem['full_reg'];?></td>
			<td class="col_long_percentage"><?php echo Util::divide($reportItem['full_reg'], $reportItem['basic_reg'], 2, true);?></td>
			<td class="col_colong"><?php echo $reportItem['full_reg_coreg'];?></td>
			<td class="col_colong_percentage"><?php echo Util::divide($reportItem['full_reg_coreg'], $reportItem['full_reg'], 2, true);?></td>
			<td class="col_update"><?php echo $reportItem['profiling_coreg_start'];?></td>
			<td class="col_coupdate"><?php echo $reportItem['profiling_coreg_end'];?></td>
			<td class="col_coupdate_percentage"><?php echo Util::divide($reportItem['profiling_coreg_end'], $reportItem['profiling_coreg_start'], 2, true);?></td>
			<td class="col_confirmed"><?php echo $reportItem['confirmed_coreg'];?></td>
			<td class="col_confirmed_percentage"><?php echo Util::divide($reportItem['confirmed_coreg'], $reportItem['basic_reg'], 2, true);?></td>
			<td class="col_coconfirmed"><?php echo $reportItem['confirmed'];?></td>
			<td class="col_coconfirmed_percentage"><?php echo Util::divide($reportItem['confirmed'], $reportItem['confirmed_coreg'], 2, true);?></td>
			<td class="col_costart"><?php echo $reportItem['daily_coreg'];?></td>
			<td class="col_coend"><?php echo $reportItem['daily_coreg'];?></td>
			<td class="col_co_percentage"><?php echo Util::divide($reportItem['daily_coreg'], $reportItem['daily_coreg'], 2, true);?></td>
			<td class="col_offer"><?php echo $reportItem['reward'];?></td>
			<td class="col_offer-user"><?php echo Util::divide($reportItem['reward'], $reportItem['basic_reg'], 2, false);?></td>
			<td class="col_rewarded"><?php echo $reportItem['token'];?></td>
			<td class="col_tokens-user"><?php echo Util::divide($reportItem['token'], $reportItem['basic_reg'], 2, false);?></td>
		</tr>
		<?php endforeach;?>
		<?php endif;?>
	</tbody>
</table>
<div class="pagination">
	<?php echo $pagination; ?>
</div>

<script
	type="text/javascript" src="<?php echo JS_DIR; ?>jquery.tablesorter.js"></script>
<script
	type="text/javascript"
	src="<?php echo JS_DIR; ?>jquery.uitablefilter.js"></script>
<script type="text/javascript">
	var $table = $('#tab1');
	$table.tablesorter();
	
	$('#site_filter').click(function(){
		var id_to_header={"site_buytype":"Buy Type",
						  "site_mediatype":"Publisher Type",
						  "site_publisher":"Publisher",
						  "site_pla":"Placement",
						  "site_campaign":"Campaign",
						  "site_creative":"Creative",
						  "site_monetization":"Monetization",
						  "site_sites":"Site"
					   	 };
		
		var $table = $('#tab1');
		var filters = new Array();
	    var elems = $('.filters_col');
	    elems.each(function(){
			var elem = $(this);
			if(elem.css('display') != 'none'){
				if(elem.val() != ""){
					filters[elem.val()] = id_to_header[elem.attr('id')];
				}
			}
		});
		console.log(filters);
	    $.uiTableFilter( $table, filters);
	});
</script>
